package com.masita.ventanas;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class VAddDescuento extends JDialog {

	public double descuento = 0;
	
	private JLabel etDescuento = new JLabel("Porcentaje Descuento");
	private JTextField tDescuento = com.masita.util.Utilidad.getDoubleJTextField();
	
	private JButton bAceptar = new JButton("Aceptar");
	
	public VAddDescuento(JDialog p){
		super(p,"Descuento",true);
		init();
	}
	
	private void init(){
		this.getContentPane().setLayout(null);
		this.getContentPane().add(etDescuento);
		etDescuento.setBounds(20,15,120,20);
		this.getContentPane().add(tDescuento);
		tDescuento.setBounds(140,15,40,20);
		tDescuento.setText("0.0");
		tDescuento.addKeyListener(new java.awt.event.KeyListener(){
			public void keyPressed(java.awt.event.KeyEvent e){
				if( e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER )
					bAceptar.doClick();				
			}
			public void keyReleased(java.awt.event.KeyEvent e){}
			public void keyTyped(java.awt.event.KeyEvent e){}
		});

		
		this.getContentPane().add(this.bAceptar);
		this.bAceptar.setBounds(60,50,80,20);
		this.bAceptar.addActionListener(new java.awt.event.ActionListener(){
			public void actionPerformed(java.awt.event.ActionEvent e){
				guardar();
				dispose();
			}
		});
	}
	
	private void guardar(){
		
		try{
			descuento = Math.abs(Double.parseDouble(this.tDescuento.getText()));
		}
		catch(Exception e){
			descuento = 0;
		}
	}
	
	public double getDescuento(){
		return this.descuento;
	}

	// TODO MOSTRAR DE LA CLASE ***************************
	public void mostrar(){
		this.setSize(205,110);
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}	
	
}
